package com.shuaqiu.sboot.error;

import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

/**
 * 用于重新定义出现在还没到controller 的错误时返回的内容
 *
 * @author Created by shuaqiu on 2017-12-10.
/* */
@Component
public class ResultErrorAttributes extends DefaultErrorAttributes implements ErrorAttributes {
    @Override
    public Map<String, Object> getErrorAttributes(final WebRequest webRequest, final boolean includeStackTrace) {
        final Map<String, Object> attributes = super.getErrorAttributes(webRequest, includeStackTrace);

        final Map<String, Object> errorAttributes = new LinkedHashMap<>();
        errorAttributes.put("success", false);
        errorAttributes.put("message", attributes.get("message"));
        return errorAttributes;
    }
}
